package com.bootdo.appsystem.controller;

import java.util.List;
import java.util.Map;

import com.bootdo.app.service.AppOrderService;
import com.bootdo.appsystem.domain.ImageinfoDO;
import com.bootdo.appsystem.domain.SellerDO;
import com.bootdo.appsystem.domain.ShouruDO;
import com.bootdo.appsystem.service.ImageinfoService;
import com.bootdo.appsystem.service.ShouruService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.appsystem.domain.OrderproductDO;
import com.bootdo.appsystem.service.OrderproductService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 
 * 
 * @author xiaoxiao
 * @email 806191255@qq.com
 * @date 2018-05-12 14:42:14
 */
 
@Controller
@RequestMapping("/appsystem/orderproduct")
public class OrderproductController {
	@Autowired
	private OrderproductService orderproductService;
	@Autowired
	private AppOrderService appOrderService;
	@Autowired
	private ShouruService shouruService;
	@Autowired
	private ImageinfoService imageinfoService;
	
	@GetMapping()
	@RequiresPermissions("appsystem:orderproduct:orderproduct")
	String Orderproduct(){
	    return "appsystem/orderproduct/orderproduct";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("appsystem:orderproduct:orderproduct")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<OrderproductDO> orderproductList = orderproductService.list(query);
		int total = orderproductService.count(query);
		PageUtils pageUtils = new PageUtils(orderproductList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("appsystem:orderproduct:add")
	String add(){
	    return "appsystem/orderproduct/add";
	}

	@GetMapping("/edit/{oid}")
	@RequiresPermissions("appsystem:orderproduct:edit")
	String edit(@PathVariable("oid") Integer oid,Model model){
		OrderproductDO orderproduct = orderproductService.get(oid);
		model.addAttribute("orderproduct", orderproduct);
	    return "appsystem/orderproduct/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("appsystem:orderproduct:add")
	public R save( OrderproductDO orderproduct){
		if(orderproductService.save(orderproduct)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("appsystem:orderproduct:edit")
	public R update( OrderproductDO orderproduct){
		orderproductService.update(orderproduct);
		return R.ok();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/editImage")
	@RequiresPermissions("appsystem:orderproduct:edit")
	public R editImage(Integer id , Integer orderPark){
        ImageinfoDO imageinfoDO = new ImageinfoDO();
        imageinfoDO.setImageid(id);
        imageinfoDO.setImagetype(orderPark);
        imageinfoService.update(imageinfoDO);
		return R.ok();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("appsystem:orderproduct:remove")
	public R remove( Integer oid){
		if(orderproductService.remove(oid)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("appsystem:orderproduct:batchRemove")
	public R remove(@RequestParam("ids[]") Integer[] oids){
		orderproductService.batchRemove(oids);
		return R.ok();
	}

	/**
	 *  生成订单
	 */
	@PostMapping("/shengcheng")
	@ResponseBody
	@RequiresPermissions("appsystem:orderproduct:shengcheng")
	public R shengcheng(@RequestParam("id")Integer id , @RequestParam("orderPark") Integer orderPark){
		appOrderService.shengChengOrderStatu(id,orderPark);
		return R.ok();
	}


	@GetMapping("/toordershouzhi")
	@RequiresPermissions("appsystem:orderproduct:ordershouzhi")
	public String toOrderShouzhi(String ordercode , Model model){
		model.addAttribute("ordercode",ordercode);
		return "appsystem/orderproduct/ordershouzhi";
	}


	/**
	*【方法解释】 订单表查看用户订单收支情况
	*【参数】
	*@Param  [params]
	*/
	@ResponseBody
	@GetMapping("/ordershouzhi")
	@RequiresPermissions("appsystem:orderproduct:ordershouzhi")
	public PageUtils orderShouzhi(@RequestParam Map<String, Object> params){
		//查询列表数据
		Query query = new Query(params);
		List<ShouruDO> shouruDOList = shouruService.list(query);
		int total = shouruService.count(query);
		PageUtils pageUtils = new PageUtils(shouruDOList, total);
		return pageUtils;
	}



	
}
